package sgd.tp2.client.net.tcp;

import java.io.IOException;
import java.io.ObjectOutputStream;
import java.net.UnknownHostException;

import javax.xml.bind.JAXBException;

import sgd.tp2.api.cdr.CDR;
import sgd.tp2.api.net.CDRFormatType;

public class TCPClientObject extends TCPClient {
	
	private ObjectOutputStream outStream = null;

	public TCPClientObject(CDRFormatType cdrFormatType, String serverAddress, int serverPort) {
		super(cdrFormatType, serverAddress, serverPort);
	}
	
	@Override
	public void startClient() throws UnknownHostException, IOException {
		super.startClient();
		outStream = new ObjectOutputStream(socket.getOutputStream());
	}

	@Override
	public void sendMessage() throws IOException, JAXBException {
		CDR cdr = CDR.getWithRandomData();

		outStream.writeObject(cdr);
		outStream.flush();
	}
}
